using System.ComponentModel.DataAnnotations;

namespace hao_Common.Logging.Options
{
    /// <summary>
    /// 日志配置选项
    /// </summary>
    public class LoggingOptions
    {
        /// <summary>
        /// 配置节名称
        /// </summary>
        public const string SectionName = "Logging";

        /// <summary>
        /// 应用程序名称
        /// </summary>
        [Required]
        public string ApplicationName { get; set; } = string.Empty;

        /// <summary>
        /// 环境名称
        /// </summary>
        public string Environment { get; set; } = "Development";

        /// <summary>
        /// 日志级别
        /// </summary>
        public string LogLevel { get; set; } = "Information";

        /// <summary>
        /// 是否启用控制台日志
        /// </summary>
        public bool EnableConsole { get; set; } = true;

        /// <summary>
        /// 是否启用文件日志
        /// </summary>
        public bool EnableFile { get; set; } = true;

        /// <summary>
        /// 文件日志配置
        /// </summary>
        public FileLoggingOptions File { get; set; } = new();

        /// <summary>
        /// 是否启用Elasticsearch日志
        /// </summary>
        public bool EnableElasticsearch { get; set; } = false;

        /// <summary>
        /// Elasticsearch配置
        /// </summary>
        public ElasticsearchOptions Elasticsearch { get; set; } = new();
    }

    /// <summary>
    /// 文件日志配置
    /// </summary>
    public class FileLoggingOptions
    {
        /// <summary>
        /// 日志文件路径
        /// </summary>
        public string Path { get; set; } = "logs/app-.log";

        /// <summary>
        /// 文件大小限制（MB）
        /// </summary>
        public int FileSizeLimitMB { get; set; } = 100;

        /// <summary>
        /// 保留文件数量
        /// </summary>
        public int RetainedFileCountLimit { get; set; } = 31;

        /// <summary>
        /// 是否按日期滚动
        /// </summary>
        public bool RollOnFileSizeLimit { get; set; } = true;
    }

    /// <summary>
    /// Elasticsearch配置
    /// </summary>
    public class ElasticsearchOptions
    {
        /// <summary>
        /// Elasticsearch服务器地址
        /// </summary>
        public string Uri { get; set; } = "http://localhost:9200";

        /// <summary>
        /// 索引名称
        /// </summary>
        public string IndexName { get; set; } = "hao-logs";

        /// <summary>
        /// 用户名
        /// </summary>
        public string? Username { get; set; }

        /// <summary>
        /// 密码
        /// </summary>
        public string? Password { get; set; }
    }
}